package com.wlyuan.open.domain.client.utils;


import com.alibaba.fastjson.JSON;
import com.wlyuan.open.domain.client.OpenClientId;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author yuanzheng
 */
@Slf4j
public class MappingOpenClient {
    public OpenClientId createOpenClientId(Long value) {
        return Optional.ofNullable(value)
                .map(OpenClientId::new)
                .orElse(null);
    }

    public List<String> stringToList(String source) {
        try {
            return JSON.parseArray(source, String.class);
        }catch (Exception e) {
            logger.error("数据转换失败: {}", source, e);
        }
        return Collections.emptyList();
    }

    public String listToString(List<String> list) {
        if(null == list) {
            return null;
        }
        return JSON.toJSONString(list);
    }
}
